home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000139_icon-group-sender _Mon Dec 15 08:30:35 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  9KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id IAA06791
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Mon, 15 Dec 1997 08:30:30 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA01610; Mon, 15 Dec 1997 08:30:31 -0700
  7. From: gep2@computek.net
  8. Date: Fri, 12 Dec 1997 23:57:18 -0600
  9. Message-Id: <199712130557.XAA04542@axp.cmpu.net>
  10. Mime-Version: 1.0
  11. Content-Type: text/plain
  12. Content-Transfer-Encoding: 7bit
  13. Subject: Extensions to `open'
  14. To: icon-group@optima.CS.Arizona.EDU
  15. X-Mailer: SPRY Mail Version: 04.00.06.17
  16. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  17. Status: RO
  18.  
  19. >I would like to propose a small but very useful extension to Icon: that
  20. it should be possible to open a directory by specifying a "d" option to
  21. the `open' function.
  22.  
  23. Personally, I wrote (some years ago) a loadable function DIRFNC (in assembler) 
  24. for SNOBOL4+ which offers similar getfirst/getnext features.  Despite having my 
  25. OWN function, I probably actually use the "shell out to DIR" technique more when 
  26. writing real programs.  Why?
  27.  
  28. 1)  it's always available, even if I haven't brought my function along to the 
  29. client site where I am
  30.  
  31. 2)  it's nearly as easy to use
  32.  
  33. >It seems that any extension to Icon ought to satisfy three criteria:
  34.   (1) It provides functionality that isn't easily achieved by other means.
  35.  
  36. And that's part of the problem... this functionality is in fact pretty easy to 
  37. achieve... if not in mainline code, then certainly in a small library 
  38. subroutine.
  39.  
  40. >  (2) It is stylistically consistent with the rest of the language and
  41. won't break existing code,.
  42.  
  43. That shouldn't be a problem.
  44.  
  45. >  (3) For a minor extension, it should take someone familiar with the
  46. implementation no more than half a day to code.  (Testing and debugging,
  47. of course, has to be added on.)
  48.  
  49. Writing such a library routine probably comes close to that.
  50.  
  51. >Icon already recognizes the existence of directories by providing the
  52. "chdir" function.  At first glance it would seem that being able to scan
  53. a directory is easy enough with the `system' function: you just call the
  54. system command for the purpose.  
  55.  
  56. Right.
  57.  
  58. >But that approach has two difficulties.
  59.  
  60. >It's very awkward to retrieve the output, since `system' returns only an
  61. exit code.  
  62.  
  63. But you were GOING to call open and read it "as a file" anyhow, right?  So you 
  64. wouldn't retrieve the output via SYSTEM anyhow.  If SYSTEM redirects the output 
  65. to a file, you can then get basically what you want (yeah, okay, you have 
  66. multiuser issues to prevent walking on some other user's file... if that 
  67. situation applies to you... but in that case you probably have to handle the 
  68. same issue in mainline code and your other file accesses anyhow).
  69.  
  70. > More significantly, the user code depends unnecessarily on
  71. the operating environment: 
  72.  
  73. This is a rather minor issue really because most users simply in reality don't 
  74. have multiple environments that they have to run their programs in.  For 
  75. example, I'd be *perfectly* happy to just have an MS-DOS/Windows version, since 
  76. I wouldn't expect to ever need to run the program in a Mac or Unix environment. 
  77.  Probably the huge majority of all computer users are in the same situation.
  78.  
  79. > in Unix you use `ls', in DOS/Windows you use
  80. `dir', and in MacOS you use something else again which I don't know.
  81.  
  82. Yes, but it's trivial under Unix to set up "dir" as an alias to "ls" and it's 
  83. nearly as easy under DOS/Windows to set up a batch file named "ls" which invokes 
  84. "dir".  Handling options is somewhat trickier, of course, but then again that 
  85. opens up a whole other can of worms which I'll get to in a moment.
  86.  
  87. > Yet directory structure is a concept common to all modern operating
  88. systems.  
  89.  
  90. Yes, but they don't all handle it in quite the same way.  For example, under 
  91. Windows 95 and NT you're allowed to have filenames which contain spaces.  You 
  92. also find that in European (and other) countries, time and date fields are 
  93. generally formatted differently than they are here in the USA.  Volume names and 
  94. drive specs (not to mention site/node/? and network addresses) are handled 
  95. differently.  Where Unix uses "/" to separate subdirectories, MS-DOS/Windows/NT 
  96. use "\".  Microsoft operating systems generally use "/" for options, while Unix 
  97. usually uses "-" to designate options.  The file attributes provided by 
  98. different systems are inconsistent:  Novell servers have an "execute permission" 
  99. for files which allows a program to be executed but not read.  Some systems' 
  100. directories contain "last accessed" date (in addition to creation or last 
  101. modification).  Some schemes have user-specific rights attached to individual 
  102. files.
  103.  
  104. > It ought to be possible to read a directory without having to
  105. resort to system-dependent code.
  106.  
  107. Agreed that that would be nice, but in reality when you're accessing directory 
  108. entries, that often (admittedly, not ALWAYS) implies you doing something that 
  109. involves a more detailed understanding of how the system directories are 
  110. organized.
  111.  
  112. Just one other example:  since Intel operating systems don't support direct 
  113. aliases to filenames, you know that the directory (if undamaged, anyhow) is 
  114. properly tree-structured and cannot contain any loops or cross-pointere.  I 
  115. don't believe that this is guaranteed under Unix systems, (is it?)
  116.  
  117. > Adding an option letter to the second argument of `open' is clearly
  118. consistent with Icon as it stands.  The associated file would then act
  119. as a generator whose result sequence consists of the names of the files
  120. in the directory.  `read' would produce the next file name in the
  121. directory; `reads' should probably produce an error when called on a
  122. directory (as it does, I believe, when called on an output file).
  123.  
  124. >As to the work involved: although I don't know the actual code, I assume
  125. that it involves going to the place where the option letters are
  126. extracted for `open' and inserting one additional case, together with the
  127. appropriate system call.  
  128.  
  129. >It also involves recording the fact that the
  130. file is a directory.  In the code for `read', it involves substituting
  131. the "get next filename" API for the "read line" API; both Unix and DOS
  132. provide such an API.
  133.  
  134. Right, but presumably the information available from each will not be formatted 
  135. in the same fashion once retrieved and returned... so much for cross-platform 
  136. common code!
  137.  
  138. So you have to in fact change not only open and read, but essentially the entire 
  139. I/O package (close, seek, etc too).  How do you handle directory opens for 
  140. OUTPUT?  How are errors reported?  Are file-type fault returned conditions 
  141. really appropriate for directories, or do you need other kinds?
  142.  
  143. The other issue is that if you're going to provide such a "read directory as a 
  144. file" feature, you really would WANT it to be consistent not just for one 
  145. language, but on a system-wide basis.  And that sounds like in a perfect world 
  146. it would be more desirable to implement it (under MS-DOS-type systems anyhow?) 
  147. as a small TSR which would intercept opens/reads/closes/etc at the MS-DOS level 
  148. (rather that at the language runtime library level) and then you could directly 
  149. use other system commands on directories too... 
  150. FIND/MORE/SORT/LIST/TYPE/PRINT/etc, and the same features that work then under 
  151. Icon would work (and the same way) under BASIC, COBOL, FORTRAN, Assembler, or 
  152. other languages too.
  153.  
  154. >Then there's another extension, perhaps even more useful but not quite
  155. as straightforward to implement: if `open' is called with a null
  156. argument, it invokes the current system's API for *dynamically*
  157. selecting a file to be opened.  This is the usual dialog that enables a
  158. user to browse the directory structure, looking for the file to be
  159. opened.  
  160.  
  161. Agreed that this is a nice extension, although again that implies that you can 
  162. use the screen (and put it back the way it was when you're done).  And 
  163. implementing that is substantially different under (say) MS-DOS than it is under 
  164. (say) Windows95.
  165.  
  166. > I have a hunch that if graphical user interfaces were common in
  167. the days when Ralph was first designing Icon, he would have included
  168. this facility.  It recognizes that programs are now used in far more
  169. interactive environments than they were in the old days.
  170.  
  171. Agreed.
  172.  
  173. But I still think that writing such routines in the classic way is at least 
  174. (most of the time) pretty easy (the interactive one less so, but then again you 
  175. probably only need to do it once).
  176.  
  177. Gordon Peterson
  178. http://www.computek.net/public/gep2/
  179. Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  180.  
  181.